package itesm.sql.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import itesm.coler.models.User;

public class UserDAO {

	ConnectionDB connectionDB;
	private static PreparedStatement insertaUsuario;
	private Connection connection;
	
	public UserDAO(){
		
	}
	public Connection getConnection(){
		return connection;
	}
	public void setConnection(Connection connection){
		this.connection = connection;
	}
	
	public void insertUser(User user){
		try {
			insertaUsuario = connection.prepareStatement("insert into user(username,firstname,middlename,lastname,gender,active,online,userType,password) values(?,?,?,?,?,?,?,?,?);");
			insertaUsuario.setString(1, user.getUserName());
			insertaUsuario.setString(2, user.getFirstName());
			insertaUsuario.setString(3, user.getMiddleName());
			insertaUsuario.setString(4, user.getLastName());
			insertaUsuario.setString(5, user.getGender()+"");
			insertaUsuario.setInt(6, 1);
			insertaUsuario.setInt(7, 0);
			insertaUsuario.setString(8, user.getUserType());
			insertaUsuario.setString(9, user.getPass());
			insertaUsuario.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
